import 'package:flutter/material.dart';
import 'package:flutter_widget/custom/custom_appbar.dart';

// ignore: must_be_immutable
class RecorderableListViewPage extends StatefulWidget {
  String name;
  RecorderableListViewPage({Key? key, required this.name}) : super(key: key);

  @override
  // ignore: no_logic_in_create_state
  _RecorderableListViewPageState createState() =>
      _RecorderableListViewPageState();
}

class _RecorderableListViewPageState extends State<RecorderableListViewPage> {
  // ignore: deprecated_member_use
  List<String> list = List.generate(100, (int i) => '$i');

  @override
  void initState() {

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppbar(widget.name, Theme.of(context).primaryColor),
      body: ReorderableListView(
        children: <Widget>[
          for (String  item in list)
            Container(
              key: ValueKey(item),
              alignment: Alignment.center,
              height: 50,
              margin: EdgeInsets.symmetric(horizontal: 25, vertical: 10),
              decoration: BoxDecoration(
                color: Colors
                    .primaries[int.parse(item) % Colors.primaries.length],
                borderRadius: BorderRadius.circular(10),
              ),
              child: Text(item,style: TextStyle(color: Colors.white),),
            )
        ],
        onReorder: (int oldIndex, int newIndex) {
          if (oldIndex < newIndex) {
            newIndex -= 1;
          }
          var child = list.removeAt(oldIndex);
          list.insert(newIndex, child);
          setState(() {

          });
        },
      ),
    );
  }
}
